package com.fjeld.middleware.jaxb;

import javax.xml.bind.annotation.*;
import java.io.Serializable;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * Created by IntelliJ IDEA.
 * User: fjeld
 * Date: 08/01/2012
 * Time: 14:17
 * <p/>
 * Describes a user
 */

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "")
@XmlRootElement(name = "V1_User")
public class V1User implements Serializable
{
    @XmlAttribute(name = "UUID", required = true)
    protected String UUID;
    @XmlAttribute(name = "FirstName")
    protected String firstName;
    @XmlAttribute(name = "LastName")
    protected String lastName;
    @XmlAttribute(name = "Password")
    protected String password;
    @XmlAttribute(name = "PasswordHint")
    protected String passwordHint;
    @XmlAttribute(name = "Gender")
    protected String gender;
    @XmlAttribute(name = "DateOfBirth")
    protected String dateOfBirth;
    @XmlAttribute(name = "Favourite")
    protected String favourite;
    @XmlAttribute(name = "City")
    protected String city;
    @XmlAttribute(name = "Country")
    protected String country;
    @XmlAttribute(name = "Status")
    protected String status;
    @XmlAttribute(name = "SessionID")
    protected String sessionID;
    @XmlAttribute(name = "LastLoginTimeInMillis")
    protected Long lastLoginTimeInMillis;
    @XmlAttribute(name = "LastInteractionTimeInMillis")
    protected Long lastInteractionTimeInMillis;
    @XmlAttribute(name = "LastInteractionType")
    protected String lastInteractionType;
    @XmlAttribute(name = "PermissionMask")
    protected String permissionMask;
    @XmlAttribute(name = "EMail")
    protected String EMail;

    public V1User()
    {
    }

    public V1User(ResultSet rs)
    {
        try
        {
            UUID = rs.getString("UUID");
            firstName = rs.getString("FirstName");
            lastName = rs.getString("LastName");
            password = rs.getString("Password");
            passwordHint = rs.getString("PasswordHint");
            gender = rs.getString("Gender");
            dateOfBirth = rs.getString("DateOfBirth");
            favourite = rs.getString("Favourite");
            city = rs.getString("City");
            country = rs.getString("Country");
            status = rs.getString("Status");
            sessionID = rs.getString("SessionID");
            lastLoginTimeInMillis = rs.getLong("LastLoginTimeInMillis");
            lastInteractionTimeInMillis = rs.getLong("LastInteractionTimeInMillis");
            lastInteractionType = rs.getString("LastInteractionType");
            permissionMask = rs.getString("PermissionMask");
            EMail = rs.getString("EMail");
        } catch (SQLException e)
        {
            e.printStackTrace();
        }
    }

    public V1User(V1Message v1Message)
    {
        UUID = v1Message.getUserID();
        firstName = "";
        lastName = "";
        password = v1Message.getPassword();
        passwordHint = "";
        gender = "";
        dateOfBirth = "";
        favourite = "";
        city = "";
        country = "";
        status = UserStatus.Active.toString();
        sessionID = "";
        lastLoginTimeInMillis = 0l;
        lastInteractionTimeInMillis = v1Message.getSendingTime();
        lastInteractionType = v1Message.getCorrespondenceType();
        permissionMask = "";
        EMail = "";
    }

    public String getUUID()
    {
        return UUID;
    }

    public void setUUID(String UUID)
    {
        this.UUID = UUID;
    }

    public String getFirstName()
    {
        return firstName;
    }

    public void setFirstName(String firstName)
    {
        this.firstName = firstName;
    }

    public String getLastName()
    {
        return lastName;
    }

    public void setLastName(String lastName)
    {
        this.lastName = lastName;
    }

    public String getPassword()
    {
        return password;
    }

    public void setPassword(String password)
    {
        this.password = password;
    }

    public String getPasswordHint()
    {
        return passwordHint;
    }

    public void setPasswordHint(String passwordHint)
    {
        this.passwordHint = passwordHint;
    }

    public String getGender()
    {
        return gender;
    }

    public void setGender(String gender)
    {
        this.gender = gender;
    }

    public String getDateOfBirth()
    {
        return dateOfBirth;
    }

    public void setDateOfBirth(String dateOfBirth)
    {
        this.dateOfBirth = dateOfBirth;
    }

    public String getFavourite()
    {
        return favourite;
    }

    public void setFavourite(String favourite)
    {
        this.favourite = favourite;
    }

    public String getCity()
    {
        return city;
    }

    public void setCity(String city)
    {
        this.city = city;
    }

    public String getCountry()
    {
        return country;
    }

    public void setCountry(String country)
    {
        this.country = country;
    }

    public String getStatus()
    {
        return status;
    }

    public void setStatus(String status)
    {
        this.status = status;
    }

    public String getSessionID()
    {
        return sessionID;
    }

    public void setSessionID(String sessionID)
    {
        this.sessionID = sessionID;
    }

    public Long getLastLoginTimeInMillis()
    {
        return lastLoginTimeInMillis;
    }

    public void setLastLoginTimeInMillis(Long lastLoginTimeInMillis)
    {
        this.lastLoginTimeInMillis = lastLoginTimeInMillis;
    }

    public Long getLastInteractionTimeInMillis()
    {
        return lastInteractionTimeInMillis;
    }

    public void setLastInteractionTimeInMillis(Long lastInteractionTimeInMillis)
    {
        this.lastInteractionTimeInMillis = lastInteractionTimeInMillis;
    }

    public String getLastInteractionType()
    {
        return lastInteractionType;
    }

    public void setLastInteractionType(String lastInteractionType)
    {
        this.lastInteractionType = lastInteractionType;
    }

    public String getPermissionMask()
    {
        return permissionMask;
    }

    public void setPermissionMask(String permissionMask)
    {
        this.permissionMask = permissionMask;
    }

    public String getEMail()
    {
        return EMail;
    }

    public void setEMail(String EMail)
    {
        this.EMail = EMail;
    }

    public static enum UserStatus
    {
        LoggedIn, LoggedOut, Active, Deactivated, Banned;
    }
}
